//
//  SettingMessageView.m
//  YIJU2.0-HD
//
//  Created by 陈柏兵 on 16/5/11.
//  Copyright © 2016年 张金国. All rights reserved.
//

#import "SettingMessageView.h"
#import "Macro.h"
#import "Masonry.h"
#import "NKColorSwitch.h"
#import "UILabel+ColorAndText.h"
#import "UIColor+RandomColor.h"
#import "CheckOffAndTitleView.h"

@interface SettingMessageView ()

@property (nonatomic, strong) UIView *MessageRemind;//消息提醒
@property (nonatomic, strong) UIView *RemindMethod;//提醒方式
@property (nonatomic, strong) UIView *RemindModel;//提醒模式
@property (nonatomic, strong) UIView *lineView;//底部分割线

@property (nonatomic, strong) UILabel *title1;
@property (nonatomic, strong) UILabel *title2;
@property (nonatomic, strong) UILabel *title3;

@property (nonatomic, strong) NKColorSwitch *RemindSwitch;//消息提醒开关

@property (nonatomic, assign) BOOL isRemind;//是否开启提醒模式
@end

@implementation SettingMessageView

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self setUpContainer];
    }
    return self;
}

#pragma mark - responder Method
- (void)switchPressed:(NKColorSwitch *)sender {
    if (sender.isOn == YES) {
        DDLogInfo(@"开关开了");
    } else {
        DDLogInfo(@"开关关了");
    }
}

#pragma mark - privte
- (void)setUpContainer {
    [self.MessageRemind mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mas_top);
        make.left.equalTo(self.mas_left);
        make.width.equalTo(self.mas_width);
        make.height.equalTo(self.mas_height).multipliedBy(1/3.0f);
    }];
    
    [self.RemindMethod mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_MessageRemind.mas_bottom);
        make.left.equalTo(self.mas_left);
        make.width.equalTo(self.mas_width);
        make.height.equalTo(self.mas_height).multipliedBy(1/3.0f);
    }];
    
    [self.RemindModel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_RemindMethod.mas_bottom);
        make.left.equalTo(self.mas_left);
        make.width.equalTo(self.mas_width);
        make.height.equalTo(self.mas_height).multipliedBy(1/3.0f);
    }];
    
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(_RemindModel.mas_bottom).offset(-0.5f);
        make.left.equalTo(_RemindModel.mas_left);
        make.width.equalTo(_RemindModel.mas_width);
        make.height.equalTo(@(0.5));
    }];
    
    
    [self.title1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_MessageRemind.mas_top).offset(FiveOffsetViewMargin);
        make.left.equalTo(_MessageRemind.mas_left).offset(TweentyOffsetViewMargin);
        make.width.equalTo(_MessageRemind.mas_width).multipliedBy(1/8.0);
        make.bottom.equalTo(_MessageRemind.mas_bottom).offset(-FiveOffsetViewMargin);
    }];
    
    [self.title2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_RemindMethod.mas_top).offset(FiveOffsetViewMargin);
        make.left.equalTo(_RemindMethod.mas_left).offset(TweentyOffsetViewMargin);
        make.width.equalTo(_RemindMethod.mas_width).multipliedBy(1/8.0);
        make.bottom.equalTo(_RemindMethod.mas_bottom).offset(-FiveOffsetViewMargin);
    }];
    
    [self.title3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_RemindModel.mas_top).offset(FiveOffsetViewMargin);
        make.left.equalTo(_RemindModel.mas_left).offset(TweentyOffsetViewMargin);
        make.width.equalTo(_RemindModel.mas_width).multipliedBy(1/8.0f);
        make.bottom.equalTo(_RemindModel.mas_bottom).offset(-FiveOffsetViewMargin);
    }];
    
    [self.RemindSwitch mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_MessageRemind.mas_top).offset(TenOffsetViewMargin);
        make.right.equalTo(_MessageRemind.mas_right).offset(-TweentyOffsetViewMargin);
        make.width.equalTo(_MessageRemind.mas_width).multipliedBy(1/8.0f);
        make.bottom.equalTo(_MessageRemind.mas_bottom).offset(-TenOffsetViewMargin);
    }];
    
    //震动勾选项
    CheckOffAndTitleView *shake = [[CheckOffAndTitleView alloc] initWithCheckIsSelected:^(BOOL isSelected) {
        if (isSelected == YES) {
            DDLogInfo(@"选中了");
        } else {
            DDLogInfo(@"取消了");
        }
    }];
    shake.backgroundColor = [UIColor clearColor];
    shake.titleString = @"震动";
    [_RemindMethod addSubview:shake];
    [shake mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_RemindMethod.mas_top).offset(TenOffsetViewMargin);
        make.right.equalTo(_RemindMethod.mas_right).offset(-TweentyOffsetViewMargin);
        make.width.equalTo(_RemindMethod.mas_width).multipliedBy(1/8.0f);
        make.bottom.equalTo(_RemindMethod.mas_bottom).offset(-TenOffsetViewMargin);
    }];
    
    //铃声勾选项
    CheckOffAndTitleView *sound = [[CheckOffAndTitleView alloc] initWithCheckIsSelected:^(BOOL isSelected) {
        if (isSelected == YES) {
            DDLogInfo(@"选中了");
        } else {
            DDLogInfo(@"取消了");
        }
    }];
    sound.backgroundColor = [UIColor clearColor];
    sound.titleString = @"铃声";
    [_RemindMethod addSubview:sound];
    [sound mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_RemindMethod.mas_top).offset(TenOffsetViewMargin);
        make.right.equalTo(shake.mas_left).offset(-TweentyOffsetViewMargin);
        make.width.equalTo(_RemindMethod.mas_width).multipliedBy(1/8.0f);
        make.bottom.equalTo(_RemindMethod.mas_bottom).offset(-TenOffsetViewMargin);
    }];
    
    //全天勾选项
    CheckOffAndTitleView *allDay = [[CheckOffAndTitleView alloc] initWithCheckIsSelected:^(BOOL isSelected) {
        _isRemind = isSelected;
        if (_isRemind == YES) {
            DDLogInfo(@"选中了");
        } else {
            DDLogInfo(@"取消了");
        }
    }];
    allDay.backgroundColor = [UIColor clearColor];
    allDay.titleString = @"全天";
    [_RemindModel addSubview:allDay];
    [allDay mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_RemindModel.mas_top).offset(TenOffsetViewMargin);
        make.right.equalTo(_RemindModel.mas_right).offset(-TweentyOffsetViewMargin);
        make.width.equalTo(_RemindModel.mas_width).multipliedBy(1/8.0f);
        make.bottom.equalTo(_RemindModel.mas_bottom).offset(-TenOffsetViewMargin);
    }];
    
    //选择时间勾选项
    CheckOffAndTitleView *someTime = [[CheckOffAndTitleView alloc] initWithCheckIsSelected:^(BOOL isSelected) {
        if (isSelected == YES) {
            DDLogInfo(@"选中了");
        } else {
            DDLogInfo(@"取消了");
        }
    }];
    someTime.backgroundColor = [UIColor clearColor];
    someTime.titleString = @"免打扰模式(9:00-22:00)";
    [_RemindModel addSubview:someTime];
    [someTime mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_RemindModel.mas_top).offset(TenOffsetViewMargin);
        make.right.equalTo(allDay.mas_left).offset(-TweentyOffsetViewMargin);
        make.width.equalTo(_RemindModel.mas_width).multipliedBy(1/2.6f);
        make.bottom.equalTo(_RemindModel.mas_bottom).offset(-TenOffsetViewMargin);
    }];
    
}

#pragma mark - getter
//第一个cell的view
- (UIView *)MessageRemind {
    if (_MessageRemind == nil) {
        _MessageRemind = [[UIView alloc] init];
        [self addSubview:_MessageRemind];
    }
    return _MessageRemind;
}

//第二个cell的view
- (UIView *)RemindMethod {
    if (_RemindMethod == nil) {
        _RemindMethod = [[UIView alloc] init];
        _RemindMethod.layer.borderWidth = 0.3;
        _RemindMethod.layer.borderColor = [UIColor lightGrayColor].CGColor;
        [self addSubview:_RemindMethod];
    }
    return _RemindMethod;
}

//第三个cell的view
- (UIView *)RemindModel {
    if (_RemindModel == nil) {
        _RemindModel = [[UIView alloc] init];
        [self addSubview:_RemindModel];
    }
    return _RemindModel;
}

- (UIView *)lineView {
    if (_lineView == nil) {
        _lineView = [[UIView alloc] init];
        _lineView.backgroundColor = [UIColor lightGrayColor];
        [_RemindModel addSubview:_lineView];
    }
    return _lineView;
}

- (UILabel *)title1 {
    if (_title1 == nil) {
        _title1 = [UILabel lableWithBackgroundColor:[UIColor clearColor] textFont:17 textColor:[UIColor blackColor] title:@"消息提醒"];
        [_MessageRemind addSubview:_title1];
    }
    return _title1;
}

- (UILabel *)title2 {
    if (_title2 == nil) {
        _title2 = [UILabel lableWithBackgroundColor:[UIColor clearColor] textFont:17 textColor:[UIColor blackColor] title:@"提醒方式"];
        [_RemindMethod addSubview:_title2];
    }
    return _title2;
}

- (UILabel *)title3 {
    if (_title3 == nil) {
        _title3 = [UILabel lableWithBackgroundColor:[UIColor clearColor] textFont:17 textColor:[UIColor blackColor] title:@"提醒模式"];
        [_RemindModel addSubview:_title3];
    }
    return _title3;
}

//开关
- (NKColorSwitch *)RemindSwitch {
    if (_RemindSwitch == nil) {
        _RemindSwitch = [[NKColorSwitch alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH/17, SCREEN_HEIGHT/40)];
        [_RemindSwitch addTarget:self action:@selector(switchPressed:) forControlEvents:UIControlEventValueChanged];
        [_RemindSwitch setTintColor:[UIColor randomColor]];
        [_RemindSwitch setOnTintColor:[UIColor randomColor]];
        [_RemindSwitch setThumbTintColor:[UIColor whiteColor]];
        [_MessageRemind addSubview:_RemindSwitch];
    }
    return _RemindSwitch;
}

@end
